#include<iostream>
#include<list>
#include<string>
using namespace std;

class Person
{
public:
	Person(string name, int age, int height)
	{
		this->m_Name = name;
		this->m_Age = age;
		this->m_Height = height;
	}

	string m_Name;
	int m_Age;
	int m_Height;
};

void PrintList(const list<Person>&l)
{
	for (list<Person>::const_iterator it = l.begin(); it != l.end(); it++)
	{
		cout << "name:" << (*it).m_Name << "\tage:" << (*it).m_Age << "\theight" << (*it).m_Height << endl;
	}
}

bool Compare(Person &p1, Person p2)
{
	if (p1.m_Age == p2.m_Age)
	{
		return p1.m_Height > p2.m_Height;
	}
	else
	{
		return p1.m_Age < p2.m_Age;
	}
}

void test01()
{
	list<Person>l;
	Person p1("ab", 20, 190);
	Person p2("bc", 40, 180);
	Person p3("cd", 30, 185);
	Person p4("yz", 23, 173);
	Person p5("zy", 23, 187);

	l.push_back(p1);
	l.push_back(p2);
	l.push_back(p3);
	l.push_back(p4);
	l.push_back(p5);

	cout << "before:" << endl;
	PrintList(l);

	cout << "------------------------------" << endl;
	cout << "after:" << endl;
	l.sort(Compare);
	PrintList(l);
}

void main()
{
	test01();


	system("pause");
}